package com.witfortos.common.utils

import android.content.SharedPreferences
import android.preference.PreferenceManager
import com.witfortos.common.base.App

/**
 *   @auther : tan
 *   time   : 2020-07-08
 */
class SPUtils {

    companion object {
        private val cookiesKey: String? = "cookiesKey";

        @Volatile
        private var INSTANCE: SPUtils? = null
        private var sp: SharedPreferences? = null;
        fun getInstance() =
                INSTANCE ?: synchronized(this) {
                    INSTANCE ?: SPUtils().also {
                        INSTANCE = it
                        sp = PreferenceManager.getDefaultSharedPreferences(App.mContext)
                    }
                }
    }

    fun addCookie(cookie: String) {
        sp!!.edit().putString(cookiesKey, cookie).apply();
    }

    fun getCookies(): String {
        return sp?.getString(cookiesKey, "").toString()
    }
}